package com.gfv.facturas.interceptores;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.gfv.comunes.Cadenas;

public class UsuarioValido extends HandlerInterceptorAdapter {

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
		HttpSession sesion = request.getSession(false);
		String cadPet;
		if (sesion!=null)
		{
			if (sesion.getAttribute("uid")!=null)
			{
				if ((Integer)sesion.getAttribute("uid")>-1)
				{
					return true;
				}
			}
		}
		cadPet=request.getServletPath();
		if (Cadenas.Left(cadPet,4).equals("/log"))
		{
			return true;
		}
		response.sendRedirect("/facturas/");
		return false;
	}

}
